package com.ruyuan.commodity.controller.seller;

import com.ruyuan.commodity.common.mamager.BrandManager;
import com.ruyuan.commodity.common.mamager.CategoryManager;
import com.ruyuan.commodity.common.mamager.GoodsParamsManager;
import com.ruyuan.commodity.model.goods.vo.BrandVO;
import com.ruyuan.commodity.model.goods.vo.CategoryVO;
import com.ruyuan.commodity.model.goods.vo.GoodsParamsGroupVO;
import com.ruyuan.commodity.open.api.annotation.Auth;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 商品分类查询controller
 */
@RestController
@RequestMapping("/seller/goods/category")
public class GoodsCategoryController {

    /**
     * 商品分类业务管理器
     */
    @Autowired
    private CategoryManager categoryManager;
    /**
     * 商品属性业务管理器
     */
    @Autowired
    private GoodsParamsManager goodsParamsManager;
    /**
     * 商品品牌业务管理器
     */
    @Autowired
    private BrandManager brandManager;

    @Auth
    @ApiOperation(value = "商品发布，获取当前登录用户选择经营类目的所有根节点")
    @GetMapping(value = "/{categoryId}/children")
    public List<CategoryVO> listCurrentUserShopManageByCategoryById(@PathVariable("categoryId") Long categoryId) {
        return categoryManager.getSellerCategory(categoryId);
    }

    @Auth
    @ApiOperation(value = "商家分类")
    @GetMapping(value = "/seller/children")
    public List<CategoryVO> listCurrentUserSellerCategory() {
        return categoryManager.listAllSellerChildren();
    }

    @Auth
    @ApiOperation(value = "商品发布，获取所选分类关联的参数信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId", value = "分类id", required = true, dataType = "int", paramType = "path"),
            @ApiImplicitParam(name = "goodsId", value = "商品id", required = true, dataType = "int", paramType = "path"),
    })
    @GetMapping(value = "/{categoryId}/{goodsId}/params")
    public List<GoodsParamsGroupVO> listCategoryParamsInfoByCategoryIdAndGoodsId(
            @PathVariable("categoryId") Long categoryId, @PathVariable("goodsId") Long goodsId) {
        return this.goodsParamsManager.queryGoodsParams(categoryId, goodsId);
    }

    @Auth
    @ApiOperation(value = "发布商品，获取所选分类关联的参数信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId", value = "分类id", required = true, dataType = "int", paramType = "path")
    })
    @GetMapping(value = "/{categoryId}/params")
    public List<GoodsParamsGroupVO> listGoodsParamsInfoByCategoryId(@PathVariable("categoryId") Long categoryId) {
        return this.goodsParamsManager.queryGoodsParams(categoryId);
    }

    @Auth
    @ApiOperation(value = "修改商品，获取所选分类关联的品牌信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId", value = "分类id", required = true, dataType = "int", paramType = "path"),
    })
    @GetMapping(value = "/{categoryId}/brands")
    public List<BrandVO> listBrandByCategoryId(@PathVariable("categoryId") Long categoryId) {
        return this.brandManager.getBrandsByCategory(categoryId);
    }

}
